package com.adamfass.tractorbeam;

import com.adamfass.jmeutil.DebugGameState;
import com.adamfass.jmeutil.DebugUtil;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Sphere;
import com.jme.system.DisplaySystem;

/**
 * Displays the title screen and all menus. When the user begins a game,
 * it invokes the listener and deactivates itsself, i.e. 
 * {@code this.setActive(false)}.
 */
public class MenuGameState extends DebugGameState {
  public interface MenuGameStateListener {
    public void handleBeginGame(GameFlow gameFlow);
  }
  
  private final MenuTree menuTree;
  
  public MenuGameState(final MenuGameStateListener menuGameStateListener) {
    super(false, true);
    
    final MenuTree.MenuTreeListener menuTreeListener = 
      new MenuTree.MenuTreeListener() {
        public void handleBeginGame(GameFlow gameFlow) {
          setActive(false);
          menuGameStateListener.handleBeginGame(gameFlow);
        }
    };
   
    menuTree = new MenuTree(menuTreeListener, getRootNode());
    menuTree.gotoTitleScreen();
  
    getRootNode().updateGeometricState(0.0f, true);
    getRootNode().updateRenderState();
  }
  
  public void update(float timePerFrame) {
    super.update(timePerFrame);
    
    menuTree.udpate(timePerFrame);
    
    DebugUtil.showDebugMarker("menu", ColorRGBA.magenta, new Vector3f(8, 0, 0));
       
    getRootNode().updateRenderState();
    getRootNode().updateGeometricState(timePerFrame, true);
  }
}
